﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace SaleOnlineSystem
{
    public partial class ProductSearch : System.Web.UI.Page
    {
        public static string content;
        public static int sizePage;
        public static int currentPage;

        public string catName;
        public static DataTable dt;
        public static int AllCat;

        protected void Page_Load(object sender, EventArgs e)
        {

            if (!Page.IsPostBack)
            {
                if (SaleOnlineSystem.Controls.SortProduct.column == null) SaleOnlineSystem.Controls.SortProduct.column = "Product_Name";
                if (SaleOnlineSystem.Controls.SortProduct.sort == null) SaleOnlineSystem.Controls.SortProduct.sort = "DESC";
                sizePage = Convert.ToInt32(ConfigurationManager.AppSettings["sizepage"].ToString());

                if (Request.QueryString["currentPage"] != null)
                {
                    if (Request.QueryString["content"] != null)
                        content = (Request.QueryString["content"].ToString());
                    else
                        Response.Redirect("Error.aspx");



                    currentPage = Convert.ToInt32(Request.QueryString["currentPage"].ToString());
                    dt = BOL.ProductManager.Instance.GetListProductsPaging("tbl_Product", "searchbox", currentPage, sizePage, content,
                                                                            "Product_Name", SaleOnlineSystem.Controls.SortProduct.sort , SaleOnlineSystem.Controls.SortProduct.column);
                }


                else
                {
                    if (Request.QueryString["content"] != null)
                        content = (Request.QueryString["content"].ToString());
                    else
                        Response.Redirect("Error.aspx");


                    dt = BOL.ProductManager.Instance.GetListProductsPaging("tbl_Product", "searchbox", 1, sizePage, content,
                                                                            "Product_Name", SaleOnlineSystem.Controls.SortProduct.sort, SaleOnlineSystem.Controls.SortProduct.column);
                    currentPage = 1;
                }


                // VIet stored dem so san pham co catID = CatID


                // string name = DAL.DCollector.DBCollector.Instance.StoredProcedureGetTableByID("tbl_Product", content,
                //        "selectcatname").Rows[0]["catname"].ToString();
                catName = "Tìm kiếm sản phẩm ";
                AllCat = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.StoredProcedureSelectWhereByID("tbl_Product", "Product_Name", content, "searchcountall").Rows[0]["count"].ToString());

                //catName = DAL.DCollector.DBCollector.Instance.StoredProcedureSelectWhereByID("tbl_Category", "*", "Category_ID1", catID,"selectwhereid").Rows[0]["Category_Name"].ToString();
            }

        }
    }
}